package com.songcha.module_main.ui.fragment.mine

import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import com.songcha.library_base.base.BaseFragment
import com.songcha.library_base.mvvm.base.BaseMvvmFragment
import com.songcha.library_business.config.VarConfig
import com.songcha.library_business.helper.AdvertCoverHelper
import com.songcha.library_business.helper.AdvertHelper
import com.songcha.library_business.util.BusinessJumpUtil
import com.songcha.library_common.util.JumpUtil
import com.songcha.library_common.util.ToastUtil
import com.songcha.module_main.R
import com.songcha.module_main.databinding.MainFragMineBinding
import com.songcha.module_main.ui.activity.about_us.AboutUsActivity
import com.songcha.module_main.ui.dialog.FeedbackDialog

class MineFragment:BaseMvvmFragment<MineViewModel,MainFragMineBinding>(), View.OnClickListener {
    init {
        TAG = MineFragment::class.java.simpleName
    }

    override fun getLayoutId(): Int {
        return R.layout.main_frag_mine
    }

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        databinding.mainLlYjfk.setOnClickListener(this)
        databinding.mainLlYszc.setOnClickListener(this)
        databinding.mainLlYhxy.setOnClickListener(this)
        databinding.mainLlGywm.setOnClickListener(this)

        initAdvert()
    }

    private fun initAdvert(){
        AdvertCoverHelper.loadAdvertByCoverXxl(requireActivity(),VarConfig.ADVERT_MINE_XXL_INFO,
            databinding.mainFlAdvertXxl,48f)
    }

    override fun initObserver() {
        viewModel.feedbackState.observe(this){data->
            if(data){
                ToastUtil.show("感谢您的反馈")
            }
        }
    }

    override fun onClick(v: View) {
        when(v.id){
            R.id.main_ll_yjfk->{
                val dialog = FeedbackDialog(v.context){content->
                    viewModel.commitFeedback(content)
                }
                dialog.show()
            }
            R.id.main_ll_yszc->{
                BusinessJumpUtil.toUserPrivacyActivity(v.context,2)
            }
            R.id.main_ll_yhxy->{
                BusinessJumpUtil.toUserPrivacyActivity(v.context,1)
            }
            R.id.main_ll_gywm->{
                JumpUtil.toActivity(v.context,AboutUsActivity::class.java)
            }
        }
    }
}